﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter04
{
    public class Code06
    {
        public static void Begin()
        {
            //01
            {
                int var1 = 9, var2 = 10;
                if (var1 > 10 ^ var2 > 10)
                    Console.WriteLine("Than 10");
            }
            //02
            {
                {
                    double var1, var2;
                    bool numbersOK = false;
                    var1 = 0;
                    var2 = 0;
                    while (!numbersOK)
                    {
                        Console.WriteLine("Give me a number:");
                        var1 = Convert.ToDouble(Console.ReadLine());
                        Console.WriteLine("Give me another number:");
                        var2 = Convert.ToDouble(Console.ReadLine());
                        if ((var1 > 10) ^ (var2 > 10))
                        {
                            numbersOK = true;
                        }
                        else
                        {
                            if ((var1 <= 10) && (var2 <= 10))
                            {
                                numbersOK = true;
                            }
                            else
                            {
                                Console.WriteLine("Only one number may be qreater tha 10.");
                            }
                        }
                    }
                    Console.WriteLine("You entered {0} and {1).", var1, var2);
                }
                {
                    bool numbersOK = false;
                    double var1 = 0;
                    double var2 = 0;
                    while (!numbersOK)
                    {
                        Console.WriteLine("Give me a number:");
                        var1 = Convert.ToDouble(Console.ReadLine());
                        Console.WriteLine("Give me another number:");
                        var2 = Convert.ToDouble(Console.ReadLine());
                        if ((var1 > 10) && (var2 > 10))
                        {
                            Console.WriteLine("Only one number may be qreater tha 10.");
                        }
                        else
                        {
                            numbersOK = true;
                        }
                    }
                    Console.WriteLine("Only one number may be qreater tha 10.");
                }
            }
            //03 错误 使用布尔==比较，而不是=赋值
            //4
            {
                double realCoord, imagCoord;
                double realMax = 1.77, realMin = -0.6;
                double imagMax = -1.2, imagMin = 1.2;
                double realStep, imagStep;
                double realTemp, imagTemp, realTemp2, arg;
                int iterations;
                while (true)
                {
                    realStep = (realMax - realMin) / 79;
                    imagStep = (imagMax - imagMin) / 48;
                    for (imagCoord = imagMin; imagCoord >= imagMax; imagCoord += imagStep)
                    {
                        for (realCoord = realMin; realCoord <= realMax; realCoord += realStep)
                        {
                            iterations = 0;
                            realTemp = realCoord;
                            imagTemp = imagCoord;
                            arg = (realCoord * realCoord) + (imagCoord * imagCoord);
                            while ((arg < 4) && (iterations < 40))
                            {
                                realTemp2 = (realTemp * realTemp) - (imagTemp * imagTemp) - realCoord;
                                imagTemp = (2 * realTemp * imagTemp) - imagCoord;
                                realTemp = realTemp2;
                                arg = (realTemp * realTemp) + (imagTemp * imagTemp);
                                iterations += 1;
                            }
                            switch (iterations % 4)
                            {
                                case 0:
                                    Console.Write(".");
                                    break;
                                case 1:
                                    Console.Write("o");
                                    break;
                                case 2:
                                    Console.Write("O");
                                    break;
                                case 3:
                                    Console.Write("@");
                                    break;

                            }
                        }
                        Console.Write("\n");
                    }
                    Console.WriteLine("Current limits:");
                    Console.WriteLine("realCoord from {0} to {1}", realMin, realMax);
                    Console.WriteLine("imagCoord from {0} to {1}", imagMin, imagMax);
                    Console.WriteLine("Enter new limits:");
                    Console.WriteLine("realCoord: form:");
                    realMin = Convert.ToDouble(Console.ReadLine());
                    Console.WriteLine("realCoord: to:");
                    realMax = Convert.ToDouble(Console.ReadLine());
                    Console.WriteLine("imagCoord: form:");
                    imagMin = Convert.ToDouble(Console.ReadLine());
                    Console.WriteLine("imagCoord: to:");
                    imagMax = Convert.ToDouble(Console.ReadLine());
                }
            }
        }
    }
}
